<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/page/common/commonConfig.jsp" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<head>
    <title>系统角色-资源树</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script src="<%=basePath%>component/layout.js"></script>
    <script src="<%=basePath%>component/toolbar.js"></script>
    <script src="<%=basePath%>component/tree.js"></script>
    <script type="text/javascript" src="<%=basePath%>dwrsystem/engine.js"></script>
    <script type="text/javascript" src="<%=basePath%>dwrsystem/interface/RoleResourceAuthorize.js"></script>
    <script type="text/javascript">
	var dhxLayout = createLayoutNormal('2U',false,true);
	var MyTree;
	var roleSystemId;
	
	function nodeOnclick(id){
		changeRightPage('<%=basePath%>system-authorize/RoleResourceBindingAction!roleSystemResourceInfo.action?roleSystemId=' + roleSystemId + '&resourceId=' + id);
	}
	
	function changeRightPage(url){
		layoutCellAttachURL(dhxLayout,'b',url);
		//dhxLayout.cells('b').attachURL(url);
	}
	
	function initTree(){
		MyTree.initMyTreeFromLayout(dhxLayout,"a");
		MyTree.setupTree('<%=basePath%>system-authorize/RoleResourceBindingAction!initResourceTree.action?roleSystemId=' + roleSystemId, nodeOnclick);
		MyTree.enableCheckBoxes();
	}
	
	function initContainerBaseLayout(){
		dhxLayout.cells('a').hideHeader();
		dhxLayout.cells('a').setWidth(Number('260'));
		if(power.getPower() != '' && power.getPowerUpdate())
			createToolbarFromDHXLayoutCell(dhxLayout.cells('a'),function(toolbar){
			    toolbar.addText("info", 1, "操作:");
			    toolbar.addSeparator("sep1", 2);
			    if(power.getPowerUpdate())toolbar.addButton("update", 5, "绑定", "link_go.png", "link_go.png");
			    toolbar.attachEvent("onClick", function(id) {
			    	if(id == 'update'){
			    		submitAllBindingChange();
			    	}
			    });
			});
		dhxLayout.cells('b').hideHeader();
	}
	
	$(function (){
		roleSystemId = '${param.roleSystemId}';
		initContainerBaseLayout();
		initTree();
	});
	
	function submitAllBindingChange(){
		var chooseIds = MyTree.getAllCheckedId();
		layoutProgressOn(dhxLayout);
  		RoleResourceAuthorize.operateResourceRoleAuthorize(chooseIds, roleSystemId, 
  			function(data){
  				if(data == true){
  					var cIds = chooseIds.split(',');
  					for(var i=0;i<cIds.length;i++){
  						MyTree.changeColor(cIds[i],'blue','white');
  					}
  					parent.parent.notifyCreater('绑定成功');
  				}else{
  					parent.parent.notifyWarn('绑定失败');
  				}
  				layoutProgressOff(dhxLayout);
  			}
  		);	
	}
    </script>
</head>

<body>
</body>

</html>
